package com.ossjk.oa.accounting.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ossjk.core.util.CommonMethod;
import com.ossjk.core.vo.PagePreNextVo;
import com.ossjk.oa.accounting.entity.CwCapitals;
import com.ossjk.oa.accounting.mapper.CwCapitalsMapper;
import com.ossjk.oa.accounting.mapper.MonthFinanceMapper;
import com.ossjk.oa.accounting.service.ICwCapitalsService;
import com.ossjk.oa.accounting.service.MonthFinanceService;
import com.ossjk.oa.accounting.vo.CwCapitalsVo;
import com.ossjk.oa.accounting.vo.MoneySumVo;
import com.ossjk.oa.accounting.vo.MonthFinanceVo;
import com.ossjk.oa.accounting.vo.StatisticsVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chair
 * @since 2020-05-14
 */
@Service
public class MontFinanceServiceImpl extends ServiceImpl<MonthFinanceMapper, CwCapitals> implements MonthFinanceService {


    @Override
    public List selectIncome(Wrapper wapper) {
        return baseMapper.selectIncome(wapper);
    }
    @Override
    public List selectByDepartment(Wrapper wapper) {
        return baseMapper.selectByDepartment(wapper);
    }

    @Override
    public MonthFinanceVo selectByfenlei(Wrapper wapper) {
        return baseMapper.selectByfenlei(wapper);
    }

    @Override
    public List selectSrZc(Integer year) {
        return baseMapper.selectSrZc(year);
    }

    @Override
    public List selectGR(Wrapper wapper) {
        return baseMapper.selectGR(wapper);
    }

    @Override
    public PagePreNextVo selectPreNext(String midMth) {

        PagePreNextVo vo = new PagePreNextVo();
        String tmp =this.baseMapper.selectPreMth(midMth);
        vo.setPre(tmp==null?" ":tmp);
        tmp =this.baseMapper.selectNextMth(midMth);
        vo.setNext(tmp==null?" ":tmp );
        vo.setCurrent(midMth);

        return vo;
    }
    public PagePreNextVo selectPreOrNextByMth(String midMth ) {

        PagePreNextVo vo = new PagePreNextVo();

        vo.setPre(this.baseMapper.selectPreMth(midMth));
        vo.setNext(this.baseMapper.selectNextMth(midMth));
        vo.setCurrent(midMth);
        //取得6个月以前

        vo.setSelectAll( this.baseMapper.selectMax12Mth( CommonMethod.getxxMthBefore(midMth,-6)     ) );

        return vo;
    }

    public Integer selectMaxMoney(){
        Integer[] integers = baseMapper.selectMaxMoney();
        Integer temp = 0;
        for (int i=0;i<integers.length;i++){
            for(int j=0;j<integers.length-i-1;j++){
                if(integers[j]<integers[j+1]){
                    temp=integers[j+1];
                    integers[j+1]=integers[j];
                    integers[j]=temp;
                }
            }
        }
        return temp;
    }
}
